package com.ruoyi.hqfinance.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.hqfinance.domain.HqCostKind;
import com.ruoyi.hqfinance.service.HqCostKindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hq/costKind")
@Api(tags = "总部财务-费用类别")
public class HqCostKindController {
    @Autowired
    private HqCostKindService hqCostKindService;

    @ApiOperation("查全部")
    @GetMapping("/selectAll")
    public R selectAll() {
        List<HqCostKind> hqCostKindList = hqCostKindService.selectAll();
        if (hqCostKindList == null || hqCostKindList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(hqCostKindList);
        }
    }
    @ApiOperation("查大类")
    @GetMapping("/oneLevel")
    public R selectOneLevel() {
        List<HqCostKind> hqCostKindList = hqCostKindService.selectByOneLevel();
        if (hqCostKindList == null || hqCostKindList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(hqCostKindList);
        }
    }
    @ApiOperation("查小类")
    @GetMapping("/twoLevel")
    public R selectTwoLevel() {
        List<HqCostKind> hqCostKindList = hqCostKindService.selectByTwoLevel();
        if (hqCostKindList == null || hqCostKindList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(hqCostKindList);
        }
    }

    @ApiOperation("查名称")
    @GetMapping("/threeLevel")
    public R selectThreeLevel() {
        List<HqCostKind> hqCostKindList = hqCostKindService.selectByThreeLevel();
        if (hqCostKindList == null || hqCostKindList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(hqCostKindList);
        }
    }

    @ApiOperation("根据大类查小类")
    @GetMapping("/selectByParentId")
    public R selectByParentId(String name) {
        List<HqCostKind> hqCostKindList = hqCostKindService.selectByParentId(name);
        if (hqCostKindList == null || hqCostKindList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(hqCostKindList);
        }
    }
    @ApiOperation("添加")
    @PostMapping("/insert")
    public R insert(@RequestBody HqCostKind hqCostKind){
        Boolean isAdd = hqCostKindService.insert(hqCostKind);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R update(@RequestBody HqCostKind hqCostKind){
        Boolean isUpdate = hqCostKindService.update(hqCostKind);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public R delete(Integer id){
        Boolean isDelete = hqCostKindService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

}
